<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form id="buscar_form" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexProtocolo.xhtml')}" value="Protocolo" update="@form" immediate="true"/> >
                    <p:commandLink   value="Caixa" update="@form" immediate="true"/>
                </div>
                <p:tabView dynamic="true" id="tabView">
                    
                    <p:tab id="Caixa" title="Caixa">
                        <table style="min-height:500px; width: 100%">
                            <tr>
                                <td style="vertical-align: top">
                                    <h:panelGrid columns="1"  styleClass="textAlignRight" columnClasses="textAlignRight">
                                        <p:dataTable id="protable" var="protocolo" 
                                                     style="width: 700px;"
                                                     value="#{managerConsultarCaixa.lstProtocolo}" >
                                            <f:facet name="header">
                                                Protocolo
                                            </f:facet>
                                            <p:column headerText="Cod">
                                                <h:outputText value="#{protocolo.id}"/>
                                            </p:column>
                                            <p:column headerText="Cliente">
                                                <h:outputText value="#{protocolo.cliente.nome}"/>
                                            </p:column>
                                            <p:column headerText="Valor">
                                                <h:outputText value="#{protocolo.valorTotalCartorio.add(protocolo.valorTotalFermojupi)}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
<!--                                                <h:outputText value="{managerConsultarCaixa.valorDoProtocolo(protocolo)}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>-->
                                            </p:column>

                                        </p:dataTable> 
                                        <p:dataTable id="pagtable" var="pag" 
                                                     style="width: 700px; vertical-align: top; margin-top: 10px;"
                                                     value="#{managerConsultarCaixa.lstPagamento}" >
                                            <f:facet name="header">
                                                Pagamento
                                            </f:facet>
                                            <p:column headerText="Titulo">
                                                <h:outputText value="#{pag.titulo}"/>
                                            </p:column>
                                            <p:column headerText="Descricao">
                                                <h:outputText value="#{pag.descricao}"/>
                                            </p:column>
                                            <p:column headerText="Valor">
                                                <h:outputText value="#{pag.valor}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                            </p:column>

                                        </p:dataTable> 

                                        <h:panelGrid columns="2"
                                                     styleClass="textAlignRight" columnClasses="textAlignRight, noMargin"
                                                     style="vertical-align: top; width: 100%; margin-top: 10px;" 
                                                     >
                                            <p:panel header="Demostrativo do Caixa / Mês" style="width: 100%;">
                                                <p:lineChart value="#{managerConsultarCaixa.categoryModel}"
                                                             legendPosition="e" title="Caixa - Mês"
                                                             minY="0" maxY="#{managerConsultarCaixa.cont}" xaxisLabel="Meses"
                                                             yaxisLabel="Valores" style="width:400px;height:250px;" />
                                            </p:panel>  
                                            <h:panelGrid columns="1" 
                                                         style="width: 100%; vertical-align: top;" 
                                                         styleClass="textAlignRight" 
                                                         columnClasses="textAlignRight">
                                                
                                                <p:panel header="Movimentação Diária" style="width: 100%; ">
                                                    <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                        <h:outputLabel value="Protocolos : "/>
                                                        <h:outputText value="#{managerConsultarCaixa.lstProtocolo.size()}"/>
                                                        <h:outputLabel value="Pagamentos : "/>
                                                        <h:outputText value="#{managerConsultarCaixa.lstPagamento.size()}"/>
                                                        <h:outputLabel value="Selos : "/>
                                                        <h:outputText value="#{managerConsultarCaixa.qtdSelos}"/>
                                                    </h:panelGrid>  
                                                </p:panel> 
                                                
                                                <p:panel header="Selos Estoque" style="width: 100%; margin-top: 10px;">
                                                    <table class="textAlignRight">
                                                        <ui:repeat value="#{managerConsultarCaixa.lstvisaoLista}" var="v">
                                                            <tr>
                                                                <td>
                                                                    <h:outputLabel value="#{v.tipoSelo.nome} : "/>
                                                                </td>
                                                                <td>
                                                                    <h:outputText value="#{v.qtd}"/>
                                                                </td>
                                                            </tr>
                                                        </ui:repeat>
                                                    </table>  
                                                </p:panel> 
                                            </h:panelGrid>
                                        </h:panelGrid>   
                                    </h:panelGrid>
                                </td>
                                <td style="vertical-align: top">
                                    <h:panelGrid columns="1"
                                                 styleClass="textAlignRight" columnClasses="textAlignRight">
                                        <p:panel  header="Cartório">  
                                            <h:panelGrid columns="2" styleClass="textAlignRight"
                                                         columnClasses="textAlignRight"  style="width:100%;">
                                                <h:outputLabel value="Total : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorCartorio}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                            </h:panelGrid>
                                        </p:panel>
                                        <p:panel header="FermoJupi" style="margin-top: 10px;">
                                            <h:panelGrid columns="2" styleClass="textAlignRight" 
                                                         columnClasses="textAlignRight"  style="width:100%;">
                                                <h:outputLabel value="Total : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorFermojupi}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                            </h:panelGrid>
                                        </p:panel>
                                        <p:panel header="Pagamentos" style="margin-top: 10px;">
                                            <h:panelGrid columns="2" styleClass="textAlignRight"
                                                         columnClasses="textAlignRight"  style="width:100%;">
                                                <h:outputLabel value="Total : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorPagamento}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                            </h:panelGrid>
                                        </p:panel>
                                        <p:panel header="Total" style="margin-top: 10px;">
                                            <h:panelGrid columns="2" styleClass="textAlignRight"
                                                         columnClasses="textAlignRight" style="width:100%;">
                                                <h:outputLabel value="Total : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorTotal}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                                <h:outputLabel value="Recebido : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorRecebido}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                                <h:outputLabel value="A Receber : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorAreceber}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                                <h:outputLabel value="Receita : "/>
                                                <h:outputText value="#{managerConsultarCaixa.valorTotal.subtract(managerConsultarCaixa.valorPagamento)}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                            </h:panelGrid>
                                        </p:panel>
                                        <p:panel header="Caixa/Mês" style="margin-top: 10px;">
                                            <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                <h:outputLabel value="Total :"/>
                                                <h:outputText value="#{managerConsultarCaixa.valorTotalMesCaixa}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                                <h:outputLabel value="Cartório :"/>
                                                <h:outputText value="#{managerConsultarCaixa.valorTotalMesCartorio}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                                <h:outputLabel value="FermoJupi :"/>
                                                <h:outputText value="#{managerConsultarCaixa.valorTotalMesFermoJupi}">
                                                    <f:convertNumber pattern="#,###,##0.00"/>
                                                </h:outputText>
                                            </h:panelGrid>

                                        </p:panel>

                                    </h:panelGrid>    
                                </td>
                            </tr>
                        </table>

                        <div class="buttonAction">
                            <p:commandButton  value="Voltar" icon="ui-icon-arrowreturnthick-1-w" 
                                              actionListener="#{managerConsultarCaixa.redirect('indexProtocolo.xhtml')}" 
                                              immediate="true"/>
                        </div> 


                    </p:tab> 

                    <p:tab id="Pesquisar" title="Pesquisar">
                        
                        <fieldset class="ui-fieldset">
                            <legend><h:outputLabel value="Filtro"/></legend>
                            <h:panelGrid columns="4"  styleClass="textAlignRight" columnClasses="textAlignRight">
                                <h:outputLabel value="Intervalo:"/>
                                <p:calendar value="#{managerConsultarPesquisarCaixa.dataini}" 
                                            mode="popup" showOn="both" pattern="dd/MM/yyyy"/>
                                <h:outputLabel value=" à "/>
                                <p:calendar value="#{managerConsultarPesquisarCaixa.datafim}"
                                            mode="popup" showOn="both" pattern="dd/MM/yyyy"/>

                            </h:panelGrid>
                        </fieldset>


                        <div class="buttonAction">
                            <p:commandButton  value="Buscar" icon="ui-icon-search" 
                                              actionListener="#{managerConsultarPesquisarCaixa.pesquisar()}"
                                              update="propestable, pagpestable, @form"/>
                            <p:commandButton  value="Voltar" icon="ui-icon-arrowreturnthick-1-w"
                                              actionListener="#{managerConsultarCaixa.redirect('indexProtocolo.xhtml')}" 
                                              immediate="true"/>
                            <p:ajaxStatus style="width:16px;height:16px;" id="ajaxStatusPanel">  
                                <f:facet name="start">  
                                    <h:graphicImage value="/media/img/loading.gif" />  
                                </f:facet>  

                                <f:facet name="complete">  
                                    <h:outputText value="" />  
                                </f:facet>  
                            </p:ajaxStatus>
                        </div>

                        <fieldset class="ui-fieldset">
                            <legend><h:outputLabel value="Resultado"/></legend>
                            <table style="min-height:500px; width: 100%">
                                <tr>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="1"  styleClass="textAlignRight" columnClasses="textAlignRight">
                                            <p:dataTable id="propestable" var="protocolo" style="width: 700px;" value="#{managerConsultarPesquisarCaixa.lstProtocolo}" >
                                                <f:facet name="header">
                                                    Protocolo
                                                </f:facet>
                                                <p:column headerText="Cod">
                                                    <h:outputText value="#{protocolo.id}"/>
                                                </p:column>
                                                <p:column headerText="Cliente">
                                                    <h:outputText value="#{protocolo.cliente.nome}"/>
                                                </p:column>
                                                <p:column headerText="Valor">
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorDoProtocolo(protocolo)}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </p:column>

                                            </p:dataTable> 
                                            <p:dataTable id="pagpestable" var="pag" 
                                                         style="width: 700px; vertical-align: top; margin-top: 10px;"
                                                         value="#{managerConsultarPesquisarCaixa.lstPagamento}" >
                                                <f:facet name="header">
                                                    Pagamento
                                                </f:facet>
                                                <p:column headerText="Titulo">
                                                    <h:outputText value="#{pag.titulo}"/>
                                                </p:column>
                                                <p:column headerText="Descricao">
                                                    <h:outputText value="#{pag.descricao}"/>
                                                </p:column>
                                                <p:column headerText="Valor">
                                                    <h:outputText value="#{pag.valor}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </p:column>

                                            </p:dataTable> 

                                            <h:panelGrid columns="2"
                                                         styleClass="textAlignRight" columnClasses="textAlignRight, noMargin"
                                                         style="vertical-align: top; width: 100%; margin-top: 10px;" 
                                                         >
                                                <p:panel header="Demostrativo do Caixa / Mês" style="width: 100%;">
                                                    <p:lineChart value="#{managerConsultarPesquisarCaixa.categoryModel}"
                                                                 legendPosition="e" title="Caixa - Mês"
                                                                 minY="0" maxY="24" xaxisLabel="Meses"
                                                                 yaxisLabel="Valores" style="width:400px;height:250px;" />
                                                </p:panel>  
                                                <h:panelGrid columns="1" 
                                                             style="width: 100%; vertical-align: top;" 
                                                             styleClass="textAlignRight" 
                                                             columnClasses="textAlignRight">
                                                    <p:panel header="Movimentação Diária" style="width: 100%; ">
                                                        <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                            <h:outputLabel value="Protocolos : "/>
                                                            <h:outputText value="#{managerConsultarPesquisarCaixa.qtdProtocolo}"/>
                                                            <h:outputLabel value="Selos : "/>
                                                            <h:outputText value="#{managerConsultarCaixa.qtdSelos}"/>
                                                        </h:panelGrid>  
                                                    </p:panel> 
                                                    <p:panel header="Selos Estoque" style="width: 100%; margin-top: 10px;">
                                                        <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                            <ui:repeat value="#{managerConsultarPesquisarCaixa.lstvisaoLista}" var="v">
                                                                <h:outputText value="#{v.tipoSelo.nome} : "/>
                                                                <h:outputText value="#{v.qtd}"/>
                                                                <br/>
                                                            </ui:repeat>
                                                        </h:panelGrid>  
                                                    </p:panel> 
                                                </h:panelGrid>
                                            </h:panelGrid>   
                                        </h:panelGrid>
                                    </td>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="1"
                                                     styleClass="textAlignRight" columnClasses="textAlignRight">
                                            <p:panel  header="Cartório">  
                                                <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                    <h:outputLabel value="Total : "/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorCartorio}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </h:panelGrid>
                                            </p:panel>
                                            <p:panel header="FermoJupi" style="margin-top: 10px;">
                                                <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                    <h:outputLabel value="Total : "/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorFermojupi}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </h:panelGrid>
                                            </p:panel>
                                            <p:panel header="Pagamentos" style="margin-top: 10px;">
                                                <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                    <h:outputLabel value="Total : "/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorPagamento}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </h:panelGrid>
                                            </p:panel>
                                            <p:panel header="Total" style="margin-top: 10px;">
                                                <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                    <h:outputLabel value="Total : "/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorTotal}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                    <h:outputLabel value="Recebido : "/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorRecebido}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                    <h:outputLabel value="A Receber : "/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorAReceber}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </h:panelGrid>
                                            </p:panel>
                                            <p:panel header="Caixa/Mês" style="margin-top: 10px;">
                                                <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">
                                                    <h:outputLabel value="Total :"/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorTotalMesCaixa}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                    <h:outputLabel value="Cartório :"/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorTotalMesCartorio}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                    <h:outputLabel value="FermoJupi :"/>
                                                    <h:outputText value="#{managerConsultarPesquisarCaixa.valorTotalMesFermoJupi}">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </h:outputText>
                                                </h:panelGrid>

                                            </p:panel>

                                        </h:panelGrid>    
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </p:tab> 
                </p:tabView> 

            </h:form>
        </ui:define>
    </ui:composition>
</html>